From 10f88db9d6a8c276173814f2e23afba75c13403c Mon Sep 17 00:00:00 2001 From: Nicolas Koch Date: Thu, 27 Aug 2015 04:58:09 +0200 Subject: [PATCH] Implement --no-fail-fast flag for cargo test. This flag can be used to force cargo to run all tests, even if previous tests failed. See #1904 --- src/bin/bench.rs | 1 + src/bin/test.rs | 3 +++ src/cargo/ops/cargo_test.rs | 17 +++++++++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/bin/bench.rs b/src/bin/bench.rs index e4b5cac0c..932dae310 100644 --- a/src/bin/bench.rs +++ b/src/bin/bench.rs @@ -68,6 +68,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { let ops = ops::TestOptions { no_run: options.flag_no_run, + no_fail_fast: false, compile_opts: ops::CompileOptions { config: config, jobs: options.flag_jobs, diff --git a/src/bin/test.rs b/src/bin/test.rs index 8366a0bad..ade460165 100644 --- a/src/bin/test.rs +++ b/src/bin/test.rs @@ -21,6 +21,7 @@ struct Options { flag_quiet: bool, flag_color: Option, flag_release: bool, + flag_no_fail_fast: bool, } pub const USAGE: &'static str = " @@ -47,6 +48,7 @@ Options: -v, --verbose Use verbose output -q, --quiet No output printed to stdout --color WHEN Coloring: auto, always, never + --no-fail-fast Run all tests regardless of failure All of the trailing arguments are passed to the test binaries generated for filtering tests and generally providing options configuring how they run. For @@ -72,6 +74,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { let ops = ops::TestOptions { no_run: options.flag_no_run, + no_fail_fast: options.flag_no_fail_fast, compile_opts: ops::CompileOptions { config: config, jobs: options.flag_jobs, diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index 9fe2f02a1..60077b060 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -9,6 +9,7 @@ use util::{self, CargoResult, ProcessError}; pub struct TestOptions<'a> { pub compile_opts: ops::CompileOptions<'a>, pub no_run: bool, + pub no_fail_fast: bool, } #[allow(deprecated)] // connect => join in 1.3 @@ -116,6 +117,7 @@ fn build_and_run<'a>(manifest_path: &Path, compile.tests.sort(); let cwd = config.cwd(); + let mut errors = Vec::new(); for &(_, ref exe) in &compile.tests { let to_display = match util::without_prefix(exe, &cwd) { Some(path) => path, @@ -131,9 +133,20 @@ fn build_and_run<'a>(manifest_path: &Path, })); match ExecEngine::exec(&mut ProcessEngine, cmd) { Ok(()) => {} - Err(e) => return Ok(Err(e)) + Err(e) => { + errors.push(e); + if !options.no_fail_fast { + break + } + } } } + if errors.is_empty() { + Ok(Ok(compile)) + } else { + // errors.len() can be > 1, if --no-fail-fast is present. + // It would be cleaner to return the list of errors instead of just the last one. + Ok(Err(errors.pop().unwrap())) + } - Ok(Ok(compile)) } -- 2.30.2